﻿using UnityEngine;
using System.Collections;
using Pathfinding;

public class AI_Pather : MonoBehaviour {

	public Transform target;

	Seeker seeker;
	Path path;
	int currentWaypoint;

	void Start() {
			seeker = GetComponent<Seeker> ();
			seeker.StartPath (transform.position, target.position, OnPathComplete );

	}

	public void OnPathComplete( Path p ) {
		if (!p.error) {
			path = p;
			currentWaypoint = 0;
		} 
		else {
			Debug.Log (p.error);
		}
	}

	void FixedUpdate() {
		if (path == null) {
			return;
		}

		if (currentWaypoint >= path.vectorPath.Count) {
			return;
		}
		transform.position = path.vectorPath [currentWaypoint];
		currentWaypoint++;
		}
}

